package com.cjzuji.rental.dao.impl;

import com.cjzuji.rental.dao.RenRZuContractDao;
import com.cjzuji.rental.mapper.OrderContractMapper;
import com.cjzuji.rental.pojo.OrderContract;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.xml.ws.Action;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
import java.util.Map;
@Service
public class RenRZuContractDaoImpl implements RenRZuContractDao {
    private static final Logger logger = LoggerFactory.getLogger(RenRZuContractDaoImpl.class);
    @Autowired
    OrderContractMapper orderContractMapper;

    @Override
    @Transactional
    public void save(List<Map<String, Object>> data, Long orderID) {
        List<OrderContract> contractList = new ArrayList<>();
        for(Map<String, Object> item : data){
            OrderContract orderContract = OrderContract.builder()
                    .orderId(orderID)
                    .contractNo(" ")
                    .title(item.get("phase_str").toString())
                    .url(item.get("origin_url").toString())
                    .addTime(item.get("times_tamp").toString())
                    .createTime(new Date())
                    .updateTime(new Date())
                    .build();
            contractList.add(orderContract);
        }
        try {
            orderContractMapper.insertBatchSomeColumn(contractList);
        }catch (Exception e){
            logger.info("订单合同添加错误" + e.getMessage());
            throw e;
        }

    }
}
